<?php
if(isset($_REQUEST['aksi_rekap'])){
	require_once('../class/class.cuti.php');
	require_once('../class/class.pegawai.php');
	require_once('../class/class.refcuti.php');

	$cutiDao=new CutiDao();

	$tglAwal=date('Y-m-d', strtotime($_POST['tglAwal']));
	$tglAkhir=date('Y-m-d', strtotime($_POST['tglAkhir']));
	$msg=false;

	$cutis=$cutiDao->getAllCutiTgl($tglAwal, $tglAkhir);
	$pegawai=array();
	$pegawaiDao= new PegawaiDao();
	$refDao= new RefCutiDao();
	$cuti=array();
	if($cutis!==false){
		$msg=true;
		for($i=0;$i<count($cutis);$i++){
			$pegawai[$i]=$pegawaiDao->getPegawai($cutis[$i]['nip']);

			$cuti[$i]=array(
				'cuti' => $cutis[$i],
				'pegawai' =>$pegawai[$i],
				'ref' => $refDao->getCuti($cutis[$i]['idJnsCuti']),
				);
		}
	}
	$data=array(
		'msg' => $msg,
		'cuti' => $cuti,
		);

	echo json_encode($data);

}

if(isset($_POST['frm_aksi'])){
	if($_POST['frm_aksi']=="cetak"){
		include_once('../class/tbs_class.php');
		include_once('../class/plugins/tbs_plugin_opentbs.php');
		require_once('../class/class.cuti.php');
		require_once('../class/class.golongan.php');
		require_once('../class/class.jabatan.php');
		require_once('../class/class.pegawai.php');
		require_once('../class/class.refcuti.php');

		$TBS = new clsTinyButStrong;
		$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

		$template = '../assets/rekap.xlsx';
		$TBS->LoadTemplate($template);

		$cutiDao=new CutiDao();

		$tglAwal=date('Y-m-d', strtotime($_POST['tgl_awal']));
		$tglAkhir=date('Y-m-d', strtotime($_POST['tgl_akhir']));
		$msg=false;

		$cutis=$cutiDao->getAllCutiTgl($tglAwal, $tglAkhir);
		$pegawai=array();
		$pegawaiDao= new PegawaiDao();
		$refDao= new RefCutiDao();
		$jabatanDao=new JabatanDao();
		$golonganDao= new GolonganDao();
		$jabatan=array();
		$golongan=array();
		$cuti=array();
		$arr=array();
		if($cutis!==false){
			$msg=true;
			for($i=0;$i<count($cutis);$i++){
				$pegawai[$i]=$pegawaiDao->getPegawai($cutis[$i]['nip']);
				$jabatan[$i]=$jabatanDao->getJabatan($pegawai[$i]['nip']);
				$golongan[$i]=$golonganDao->getGolongan($pegawai[$i]['gol']);
				$cuti[$i]=array(
					'nip' =>$cutis[$i]['nip'],
					'nama' =>$pegawai[$i]['nama'],
					'golongan'=>$golongan[$i]['nmgol']." s.d. ".$golongan[$i]['pangkat'],
					'jabatan' =>$jabatan[$i]['jabatan'],
					'tglCuti' =>$cutis[$i]['tglAwal']." s.d. ".$cutis[$i]['tglAkhir'],
					'ref' =>$refDao->getCuti($cutis[$i]['idJnsCuti']),
					'jmlHari' =>$cutis[$i]['jmlHari'],
					);
			}
		}
		//print_r($cuti);
		$TBS->MergeBlock('a', $cuti);
		
		$output_file_name="rekap_tgl_".date('Y-m-d').".xlsx";
		$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name);

	}
}

?>